<?php

namespace app\backstage\service;

use think\Db;

class AdPositionService
{
	protected static $table = 'ad_position';

	/**
	 * 分页获取数据
	 * @Author   fanzhongxing
	 * @DateTime 2020-06-10T23:09:41+0800
	 * @param    [type]                   $whereMap [description]
	 * @param    [type]                   $order    [description]
	 * @param    string                   $fields   [description]
	 * @param    integer                  $pageSize [description]
	 * @return   [type]                             [description]
	 */
	public static function pageList($whereMap, $order, $fields = '*', $pageSize = 10)
	{
		return Db::name(self::$table)->where($whereMap)->order($order)->field($fields)->paginate($pageSize);
	}

	/**
	 * 获取信息
	 * @Author   fanzhongxing
	 * @DateTime 2020-06-10T22:52:30+0800
	 * @param    [type]                   $field  [description]
	 * @param    [type]                   $value  [description]
	 * @param    string                   $fields [description]
	 * @return   [type]                           [description]
	 */
	public static function getInfo($field, $value, $fields = '*') 
	{
		return Db::name(self::$table)->where($field, $value)->field($fields)->find();
	}

	/**
	 * 获取列表
	 * @Author   fanzhongxing
	 * @DateTime 2020-06-10T23:17:16+0800
	 * @param    [type]                   $whereMap [description]
	 * @param    [type]                   $fields   [description]
	 * @return   [type]                             [description]
	 */
	public static function getList($whereMap, $fields)
	{
		return Db::name(self::$table)->where($whereMap)->field($fields)->select();
	}

	/**
	 * 添加
	 * @Author   fanzhongxing
	 * @DateTime 2020-06-10T22:55:30+0800
	 * @param    [type]                   $data [description]
	 */
	public static function add($data)
	{
		$result = Db::name(self::$table)->insert($data);
		if (!$result) {
			return false;
		}
		return true;
	}

	/**
	 * 通过id删除
	 * @Author   fanzhongxing
	 * @DateTime 2020-06-10T22:56:08+0800
	 * @param    [type]                   $id [description]
	 * @return   [type]                       [description]
	 */
	public static function del($id)
	{
		$result = Db::name(self::$table)->where('id', $id)->delete();
		if (!$result) {
			return false;
		}
		return true;
	}

	/**
	 * 更新
	 * @Author   fanzhongxing
	 * @DateTime 2020-06-10T22:58:02+0800
	 * @param    [type]                   $field [字段]
	 * @param    [type]                   $value [值]
	 * @param    [type]                   $data  [description]
	 * @return   [type]                          [description]
	 */
	public static function update($field, $value, $data)
	{
		$result = Db::name(self::$table)->where($field, $value)->update($data);
		if (!$result) {
			return false;
		}
		return true;
	}
}